<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-wisDataSource-edit"
			th:object="${wisDataSource}" autocomplete="off">
			<input id="id" name="id" th:field="*{id}" type="hidden">
			<div class="form-group">
				<label class="col-sm-2 control-label"><span class="red">*</span>名称：</label>
				<div class="col-sm-8">
					<input id="name" name="name" th:field="*{name}" class="form-control " type="text" maxlength="64" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label"><span class="red">*</span>类型：</label>
				<div class="col-sm-8">
					<select id="dialect" name="dialect" class="form-control m-b" required th:field="*{dialect}">
	                    <option value="">--请选择--</option>
	                    <option value="mysql">MySQL</option>
	                    <option value="oracle">ORACLE</option>
	                    <option value="sqlserver">SQLServer</option>
	                </select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label"><span class="red">*</span>主机：</label>
				<div class="col-sm-8">
					<input id="host" name="host" th:field="*{host}" class="form-control " type="text" maxlength="64" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label"><span class="red">*</span>登陆名：</label>
				<div class="col-sm-8">
					<input id="username" name="username" th:field="*{username}" class="form-control " type="text" maxlength="64" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label"><span class="red">*</span>密码：</label>
				<div class="col-sm-8">
					<input id="password" name="password" th:field="*{password}" class="form-control " type="text" maxlength="64" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label"><span class="red">*</span>端口号：</label>
				<div class="col-sm-8">
					<input id="port" name="port" th:field="*{port}" class="form-control " type="text" maxlength="32" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label"><span class="red">*</span>数据库：</label>
				<div class="col-sm-8">
					<input id="dbName" name="dbName" th:field="*{dbName}" class="form-control " type="text" maxlength="32" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label"><span class="red">*</span>状态：</label>
				<div class="col-sm-8">
					<label class="radio-box"><input type="radio" th:field="*{state}" value="1" id="state1" name="state">可用</label>
	                <label class="radio-box"><input type="radio" th:field="*{state}" value="0" id="state2" name="state">禁用</label>
				</div>
			</div>
			<div class="form-group">
	            <div class="form-control-static col-sm-offset-10 buttonleft">
	                <button type="button" class="btn btn-success" onclick="testJdbc() ;">测试</button>
	            </div>
        	</div>
		</form>
	</div>
	<div th:include="include::footer"></div>
	<script type="text/javascript">
		var prefix = ctx + "quartz/wisDataSource"
		function submitHandler() {
			if ($.validate.form()) {
				$.operate.save(prefix + "/edit", $('#form-wisDataSource-edit').serialize());
			}
		}
		
		function testJdbc() {
    		var url = prefix + '/testJdbc' ;
    		if ($.validate.form()) {
    			$.modal.loading("正在处理中，请稍后...");
	        	var config = {
	    	        url: url,
	    	        type: 'post',
	    	        dataType: 'json',
	    	        data: $('#form-wisDataSource-edit').serialize(),
	    	        success: function(result) {
	    	        	if(result.code == 0 ) {
	    	        		$.modal.msgSuccess('链接成功...........');
	    	        		$('#state1').parent().addClass('checked') ;
	    	        		$("#state1").attr("checked","checked");
	    	        		$("#state2").removeAttr("checked");
	    	        		$('#state2').parent().removeClass('checked') ;
	    	        	} else {
	    	        		$('#state2').parent().addClass('checked') ;
	    	        		$("#state2").attr("checked","checked");
	    	        		$("#state1").removeAttr("checked");
	    	        		$('#state1').parent().removeClass('checked') ;
	    	        	}

        	        	$.modal.closeLoading() ;
	    	        }
	    	    };
	    	    $.ajax(config)
    		}
		}
	</script>
</body>
</html>
